<?php
class Cip_categories_m extends MY_Model {
	public function get_category_list()
	{
		return $this->db
			->get('cip_categories')
			->result();
	}
	/**
	 * Insert a new category into the database
	 * @access public
	 * @param array $input The data to insert
	 * @return string
	 */
	public function insert($input = array())
	{
		$this->load->helper('text');
		$id = parent::insert(array(
			'name'=>$input['name'],
			'slug'=>url_title(strtolower(convert_accented_characters($input['name'])))
		));
		
		return $id;
	}
	/**
	 * Update an existing category
	 * @access public
	 * @param int $id The ID of the category
	 * @param array $input The data to update
	 * @return bool
	 */
	public function update($id, $input)
	{
		return parent::update($id, array(
			'name'	=> $input['name'],
		        'slug'	=> url_title(strtolower(convert_accented_characters($input['name'])))
		));
	}
	public function updateDelete($id, $input)
	{
		return parent::update($id, array(
			'name'	=> $input['name'],
		    'slug'	=> url_title(strtolower(convert_accented_characters($input['name']))),
			'deleted'	=> $input['deleted']
		));
	}
	/**
	 * Callback method for validating the title
	 * @access public
	 * @param string $title The title to validate
	 * @return mixed
	 */
	public function check_title($title = '')
	{
		return parent::count_by('name', $title) > 0;
	}
}